<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>订单管理</title>
	<link rel="stylesheet" href="/layui/css/layui.css">
	<link rel="stylesheet" href="/hyqcss/public.css">
	<style type="text/css">
		body{
			background: #e9e9e9;
		}
		/*公共头部带搜索*/
		.public_container{
			margin: 20px;
			background: #fff;
		}
		.public_title_container{
			height: 54px;
			padding: 0 20px;
			font-size: 14px;
			display: flex;
			align-items: center;
			background: #f9f9f9;
			border-bottom: 1px solid #f0f0f0;
		}
		.public_title_container a{
			margin-right: 30px;
			height: 54px;
			line-height: 54px;
			cursor: pointer;
		}
		.public_title_active{
			color: #1E9FFF;
			border-bottom: 1px solid #1E9FFF;
		}
		.public_buttonSearch_container{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20px;
			background: #fff;
		}
		.public_buttonSearch_container a{
			color: #fff;
			background-color: #2f54eb;
			text-shadow: 0 -1px 0 rgba(0,0,0,.12);
			height: 24px;
			padding: 4px 15px;
			font-size: 14px;
			border-radius: 2px;
			display: flex;
			align-items: center;
			cursor: pointer;
		}
		.public_Search_container{
			position: relative;
		}
		.public_Search_container input{
			width: 240px;
			height: 32px;
			border: 1px solid #d9d9d9;
		}
		.public_Search_container i{
			position: absolute;
			bottom: 6px;
			right: 10px;
			cursor: pointer;
		}
		/*公共头部带搜索 end*/
		.public_table_container{
			padding: 0 20px 20px 20px;
		}

		.public_tip_container{
			margin: 20px;
		}
	</style>
</head>
<body>
	<div class="public_tip_container">
		<button class="layui-btn layui-btn-primary import-file" data-id style="background-color: #1890ff;border: none;color: #ffffff;">导入订单</button>
		<button class="layui-btn layui-btn-primary batch-delete-order" data-id style="background-color: #1890ff;border: none;color: #ffffff;">批量删除订单</button>
		<span class="layui-btn layui-btn-primary" onclick="copyToClip('{$toolbarUrl}')">复制工具栏URL</span>
	</div>
	<div class="public_container">
		<!-- /*公共头部带搜索*/ -->
		<div class="public_content">
			<div class="public_title_container">
				<a href="javascript::viod(0)">店铺管理</a>
				<a href="javascript::viod(0)" class="public_title_active">订单管理</a>
			</div>
		</div>
		<div class="public_table_container">
			<form class="layui-form client-filter" action="" id="orderSelect">
	          <div class="layui-inline" style="padding-top: 20px;">
	            <label class="layui-form-label">订单号</label>
	            <div class="layui-input-inline">
	              <input type="text" name="orderNumber" placeholder="请输入订单号" value="{$orderNumber}" autocomplete="off" class="layui-input" style="padding-right: 24px;">
	              <i class="layui-icon layui-icon-search" style="position: absolute;right: 5px;top: 11px;color: #999;"></i>
	            </div>
	          </div>
	          <div class="layui-inline" style="padding-top: 20px;">
	            <label class="layui-form-label">店铺：</label>
	            <div class="layui-input-inline">
	              <select name="shop" id="">
	                <option value=""></option>
	                {loop $shop_list as $shops}
	                <option value="{$shops->id}" {if $shop == $shops->id}selected{/if}>{$h->get_shop_by_id($shops->id)['shop_name']}</option>
	                {/loop}
	              </select>
	            </div>
	          </div>
	          <div class="layui-inline" style="padding-top: 20px;">
	            <label class="layui-form-label">所属员工：</label>
	            <div class="layui-input-inline">
	              <select name="qyUser" id="">
	                <option value=""></option>
	                {loop $qy_user_list as $qy_user}
	                <option value="{$qy_user->id}" {if $qyUser == $qy_user->id}selected{/if}>{$qy_user->name}</option>
	                {/loop}
	              </select>
	            </div>
	          </div>
	          <div class="layui-inline" style="padding-top: 20px;">
	            <label class="layui-form-label">订单状态：</label>
	            <div class="layui-input-inline">
	              <select name="orderStatus" id="">
	                <option value=""></option>
	                {loop $order_status_list as $order_status}
	                <option value="{$order_status['order_status']}" {if $orderStatus == $order_status['order_status']}selected{/if}>{$order_status['order_status']}</option>
	                {/loop}
	              </select>
	            </div>
	          </div>
	          <div class="layui-inline" style="padding-top: 20px;">
	            <label class="layui-form-label">下单时间：</label>
	            <div class="layui-input-inline">
	              <input type="text" class="layui-input" name="payTime" id="payTime" value="{$payTime}" placeholder="开始日期 ~ 结束日期" autocomplete="off">
	            </div>
	          </div>
	          <div class="layui-inline" style="padding-top: 20px;">
	            <label class="layui-form-label"></label>
	            <div class="layui-input-inline">
	              <button class="layui-btn layui-btn-normal" lay-submit lay-filter="">查询</button>
	              <button class="layui-btn layui-btn-primary reset" >重置</button>
	            </div>
	          </div>
	        </form>
		</div>
			<div class="public_table_container">
				<table class="layui-table" lay-skin="line">
					<thead>
						<tr>
							<th>购买客户</th>
							<th>所属员工</th>
							<th>手机号</th>
							<th>店铺名称</th>
							<th>订单号</th>
							<th>商品名</th>
							<th>数量	</th>
							<th>订单金额</th>
							<th>订单状态</th>
							<th>下单时间</th>
							<th>操作</th>
						</tr> 
					</thead>
					<tbody>
						{loop $order_list as $order}
						<tr>
							<td>{$order->externalcontact_name}</td>
							<td>{$order->leaders}</td>
							<td>{$order->externalcontact_phone}</td>
							<td>{$h->get_shop_by_id($order->shop_id)['shop_name']}</td>
							<td>{$order->order_number}</td>
							<td>{$order->product_name}</td>
							<td>{$order->product_num}</td>
							<td>{$order->product_price}</td>
							<td>{$order->order_status}</td>
							<td>{date('Y-m-d H:i:s',$order->pay_time)}</td>
							<td>
								<button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="del_order('{$order->id}')">删除</button>
							</td>
						</tr>
						{/loop}
					</tbody>
				</table>
			</div>	 
		<!-- 公共表格部分 end-->
		<div class="main-container-h pageing-container-h">
	        <div class="pageing-content-h">
	           <span>{$p->totalnum}条/{$p->totalpage}页</span> 
	        </div>
			<ul class="pageing-content-h">
	           {P weidogsadmin}
			</ul>
	    </div>
	</div>
	<div class="layui-form" id="batchDeleteOrderDiv" style="display: none;padding: 30px;" >
		<form id="batchDeleteOrder" class="layui-form">
			<div class="" style="">
	          <h2 class="" style="text-align: center; font-size: 20px; font-weight: bold; padding-bottom: 20px;"> 批量删除订单 </h2>
	          <div class="layui-form-item">
	              <label class="layui-form-label">删除方式:</label>
	              <div class="layui-input-block">
        			 <input type="radio" name="" value="1" title="按照店铺删除订单" checked lay-filter="">
	              </div>
	          </div>
	          <div class="layui-form-item">
	              <label class="layui-form-label">选择店铺:</label>
	              <div class="layui-input-block">
	                <select name="shopId" id="shopId" value="">
	                  <option value=""></option>
	                  {loop $shop_list as $list}
	                  <option value="{$list->id}">{$list->shop_name}</option>
	                  {/loop}
	                </select>
	              </div>
	          </div>
	        </div>
	        <div class="" style="display: flex; justify-content: flex-end;margin-top: 100px;">
	          <button id="" type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="parent.layer.closeAll()" style=""> 取消</button>
	          <a id="" type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="batchDeleteOrder" style=""> 删除</a>
	        </div>
		</form>
	</div>
	<script src="/cdn/jquery.js"></script>
	<script src="/layui/layui.js"></script>
	<script src="/js/ajax.js"></script>
	<script type="text/javascript">
		// 弹窗
		layui.use('layer', function(){
			var layer = layui.layer;
		});
		//时间选择器
		layui.use('laydate', function(){
	      var laydate = layui.laydate;

	      //日期范围
	      laydate.render({ elem: '#payTime' ,range: true })
	    })
		// 表单
		layui.use('form', function(){
			var form = layui.form;

		  	$("button.reset").click(function(){
		  		// $("#orderSelect")[0].reset();
		  		var reset = false;
				$("#orderSelect").find('input[type=text],select').each(function() {
					console.log($(this).val());
					if($(this).val()){
						reset = true;
					}
			        $(this).val('');
			    });
				form.render();
				if(reset){
					location.reload();
				}
				return;
			})

			 // 监听提交
		  form.on('submit(batchDeleteOrder)', function(data){
		  	// layer.msg(JSON.stringify(data.field));
		  	// return false;
		  	var id = $("#shopId").val();
		  	myAjaxPost(false, true, 'batch_delete_order.html', { id:id}, function (resp) {
			        if (resp.status == 'success') {
			            layer.msg(resp.msg);
						setTimeout(function(){
							location.reload();
						},500);
			        }else{
			            layer.msg(resp.msg);
			        }
				});
		  	});
		});

		$('.import-file').on('click',function(){
			let  id = $(this).data('id');
			layer.open({
				type: 2,
				title: '导入订单',
				shadeClose: true,
				shade: 0.2,
				area: ['700px', '450px'],
				content: 'import_order.html?id='+id
			});
		})
	</script>
	<script type="text/javascript">
		$(".public_title_container a").click(function(e){
			if($(this).hasClass('active')) return;
			location.href = 'index.html';
		})

		function copyToClip(content, message) {
			var aux = document.createElement("input"); 
			aux.setAttribute("value", content); 
			document.body.appendChild(aux); 
			aux.select();
			document.execCommand("copy"); 
			document.body.removeChild(aux);
			if (message == null) {
				layer.msg("复制成功");
			} else{
				layer.msg(message);
			}
		}
	</script>
	<script type="text/javascript">
		$(".batch-delete-order").on('click',function(){
			layer.open({
		        type: 1,
		        title: '批量删除订单',
		        shadeClose: true,
		        shade: 0.2,
		        area: ['700px', '420px'],
		        content: $("#batchDeleteOrderDiv")
		    });
		})
		function del_order(id){
            myAjaxPost(false, true, 'del_order.html', { id:id}, function (resp) {
                 layer.msg(resp.msg);
                if (resp.status == 'success') {
					setTimeout(function(){
						location.reload();
					},500);
		        }
            })
        }
	</script>
</body>
</html>